package com.example.infrastructure.api.person.validation;

import com.example.infrastructure.api.person.validation.annotation.Mobile;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.regex.Pattern;

/**
 * TODO
 *
 * @author lxh
 * @date 2020/11/23 下午3:35
 **/
public class MobileValidator implements ConstraintValidator<Mobile, String> {
    private static final Pattern PATTERN =
            Pattern.compile("^((13[0-9])|(14[5,7])|(15[0-3,5-9])|(17[0,3,5-8])|(18[0-9])|166|198|199|(147))\\d{8}$");

    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        return PATTERN.matcher(value).matches();
    }
}
